package com.eascs.web.o2o.web.aging.service;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.eascs.web.o2o.web.aging.dao.BaseDmDao;
import com.eascs.web.o2o.web.aging.entity.HREmployeeAuditorEntity;
import com.eascs.web.sso.User;

@Repository
public class HREmplAuditorDao extends BaseDmDao{

	public List<HREmployeeAuditorEntity> findRelationEntityByEmployeeNo(HREmployeeAuditorEntity hrEmployeeAuditorEntity) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.* FROM hr_employeeauditor t WHERE 1=1 AND t.is_del='N' AND t.EMPLOYEENO = ? ");
		return this.findEntitys(sql.toString(), HREmployeeAuditorEntity.class, hrEmployeeAuditorEntity.getEmployeeNo());
	}

	public List<HREmployeeAuditorEntity> findRelationByEmployeeNo(HREmployeeAuditorEntity entity) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.* FROM hr_employeeauditor t WHERE 1=1 AND t.is_del='N' AND t.EMPLOYEENO = ? ");
		return this.findEntitys(sql.toString(), HREmployeeAuditorEntity.class, entity.getEmployeeNo());
	}
	
	
	public List<HREmployeeAuditorEntity> getEmployeeEntity(String employNo, String auditorType) {
		String sql = "SELECT * from hr_employeeauditor t where 1=1 AND t.is_del='N' AND t.EMPLOYEENO = ? and t.AUDITORTYPE = ?";
		return jdbcSessionBidm.findEntitys(sql, HREmployeeAuditorEntity.class, employNo, auditorType);
	}
	
	public List<HREmployeeAuditorEntity> getEmployeeByAuditorNo(String auditorNo, String auditorType) {
		String sql = "SELECT * from hr_employeeauditor t where 1=1 AND t.is_del='N' AND t.AUDITORNO = ? and t.AUDITORTYPE = ?";
		return jdbcSessionBidm.findEntitys(sql,HREmployeeAuditorEntity.class,auditorNo, auditorType);
	}

	public List<HREmployeeAuditorEntity> getAuditorWithNo(String employNo) {
		String sql = "SELECT * from hr_employeeauditor t where 1=1 AND t.is_del='N' AND t.EMPLOYEENO = ?";
		return jdbcSessionBidm.findEntitys(sql, HREmployeeAuditorEntity.class, employNo);
	}

	public HREmployeeAuditorEntity getEmployeeEntity(String employNo, String auditorType, String auditorNo) {
		String sql = "SELECT * from hr_employeeauditor t where 1=1 AND t.is_del='N' AND t.EMPLOYEENO = ? and t.AUDITORTYPE = ? and t.AUDITORNO = ?";
		return jdbcSessionBidm.findEntity(sql, HREmployeeAuditorEntity.class, employNo, auditorType, auditorNo);
	}


	public boolean updateEmployeeEntity(String employNo, String auditorNo, String auditorName,User user) {
		String userNo = user.getNo();
		String cname = user.getCname();
		Date now =new Date();
		String sql = "UPDATE hr_employeeauditor SET AUDITORNO=?,AUDITORNAME=?,op_psnNo=?,op_psn=?,op_date=? WHERE EMPLOYEEAUDITORNO=?";
		int result = jdbcSessionBidm.execute(sql,new Object[]{auditorNo, auditorName,userNo,cname,now,employNo});
		return result > 0 ? true : false; 
	}
}
